package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.R;
import com.atguigu.jxc.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @PostMapping("loadGoodsType")
    public String loadGoodsType(){
        return goodsTypeService.loadTypeList();
    }

    @PostMapping("save")
    public R save(@RequestParam("goodsTypeName") String goodsTypeName,
                  @RequestParam("pId") Integer pId){
        int save = goodsTypeService.save(goodsTypeName, pId);
        return R.ok(100,"保存商品分类成功",null);
    }

    @PostMapping("delete")
    public R delete(@RequestParam("goodsTypeId") String goodsTypeId){
        int row = goodsTypeService.deleteByPId(goodsTypeId);
        return R.ok(100,"删除成功",null);
    }
}
